Bite 340. Update and delete food objects
Login and get codingNow that we're able to create and retrieve
Foodobjects, it's time to add code to update and delete them.Create the two corresponding endpoints:
1. To update, the API should
1. receive a
PUTrequest with theFoodobject's id and new / updated object2. update the item in the
foodsdictionary (to keep it simple, no need to update individual attributes, just swap out the wholeFoodobject matching itsid)3. return the updated item.
2. To delete the API should
1. receive a
DELETErequest with the id of thefoodto be deleted2. delete it from the
foodsdictionary3. return a respone of
{"ok": True}(as found here).* We use
PUTbecause we're replacing the whole item. For a partial update,PATCHwould be the more appropriate HTTP verb / action.For both endpoints raise an
HTTPExceptionwith astatus_codeof404and message (detail) ofFood not found, when theidpassed in is not in thefoodsdictionary.WIN: You have a simple API for food objects up and running with minimal code! We still need to add authentication, but first we'll make two more Pydantic models so that a user can start logging daily food intake.
147 out of 151 users completed this Bite.
Will you be the 148th person to crack this Bite?
Resolution time: ~36 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 5.0 on a 1-10 difficulty scale.
» Up for a challenge? 💪